package com.xhtt.modules.photo.entity;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.xhtt.common.file.FileInfoModel;
import com.xhtt.common.utils.DateUtils;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 现场拍照装车台拍照
 * </p>
 *
 * @author xj
 * @since 2019-02-14
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class PhotoStagePhoto extends Model<PhotoCustomer> {

    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 客户id
     */
    private Integer customerId;

    /**
     * 客户名称
     */
    private String customerName;

    /**
     * 产品id
     */
    private Integer productId;

    /**
     * 产品名称
     */
    private String productName;

    /**
     * 装车台id
     */
    private Integer stageId;

    /**
     * 装车台名称
     */
    private String stageName;

    /**
     * 装车车号
     */
    private String carNo;

    /**
     * 装车罐号
     */
    private String potNo;

    /**
     * 照片json
     */
    private String photoFile;

    /**
     * 照片集合
     */
    @TableField(exist = false)
    private List<FileInfoModel> fileInfoModels;

    /**
     * 备注
     */
    private String memo;

    /**
     * 创建时间
     */
    private LocalDateTime createTime;

    @TableField(exist = false)
    private String createTimeStr;

    /**
     * 创建人名称
     */
    private String createUserName;

    /**
     * 最后一次调整时间
     */
    @TableField(update = "now()")
    private LocalDateTime updateTime;

    /**
     * 创建者ID，人工系统创建为0
     */
    private Integer createUserId;

    /**
     * 最后一次调整者ID
     */
    private Integer updateUserId;

    public String getCreateTimeStr() {
        if (createTime != null) {
            return DateUtils.dtf.format(createTime);
        }
        return "";
    }

    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    public List<FileInfoModel> getFileInfoModels() {
        if (StringUtils.isNotEmpty(photoFile)) {
            return JSON.parseArray(photoFile, FileInfoModel.class);
        } else {
            return fileInfoModels;
        }
    }

}
